<#include "../common/_home.ftl">
<@html>
<@head>
	<script type="text/javascript" src="/js/angular.min.js"></script>
	<script type="text/javascript" src="/js/jquery-1.9.1.min.js"></script>
	<link rel="stylesheet" href="media/css/login.css">
</@head>

<body ng-app='app'>
<div class="container-fluid"  ng-controller="UserController">
	<div class="clearfix"></div>
	<!-- BEGIN PAGE BODY-->
 	
			<div class="container">			
				<section id="content">
				<form class="form-horizontal" onSubmit="return false;">
						<div class="control-group">
						<h1>用户注册</h1>
						<div>
							<input type="text" placeholder="用户名" id="username" ng-model="user.name"/>
						</div>
						<div>
							<input type="password" placeholder="密码" id="password" ng-model="user.password" />
						</div>
						<div>
							<input type="password" placeholder="确认密码" id="re_password" ng-model="user.re_password" />
						</div>
						<div>
							<input type="submit" value="提交" ng-click="save();"/>
							<a href="/index">已注册？点击登录</a>
						</div>
					  </form>
					  </section>
 	</div>
 	<!-- END PAGE BODY-->
	<div class="clearfix"></div>
</div>

<@plugin/>
	<!-- END CORE PLUGINS -->
	
<script>

var app = angular.module('app', []);

app.controller('UserController', function($scope, $http){
	$scope.save = function(){
		if (!$scope.user.name) {
			alert("请输入正确用户名！");
			return;
		}else if ($scope.user.name.length > 25) {
			alert("用户名长度超长！");
			return;
		}
		
		if (!$scope.user.password) {
			alert("请输入密码！");
			return;
		}
		if ($scope.user.password != $scope.user.re_password) {
			alert("两次密码输入不一致！");
			return;
		}	
		
		$http.post("user/edit?user="+angular.toJson($scope.user)).success(function(data){
			if (data.status == 1) {
				alert("保存成功！");
				//确定后返回主页面
				window.location.href="/index";
			}else {
				alert(data.info);
			}
		});
	}
});

</script>
</body>
</@html>